﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Confucius.utils;

namespace Confucius.entity
{
    /// <summary>
    /// Author:Liangchuan Gu
    /// date:2012-04-08
    /// </summary>
    public class Quest
    {
        private string title;

        public string Title
        {
            get { return title; }
            set { title = value; }
        }

        private string questID;

        public string QuestID
        {
            get { return questID; }
            set { questID = value; }
        }

        private string iconID;

        public string IconID
        {
            get { return iconID; }
            set { iconID = value; }
        }

        private string startText;

        public string StartText
        {
            get { return startText; }
            set { startText = value; }
        }

        private string completeText;

        public string CompleteText
        {
            get { return completeText; }
            set { completeText = value; }
        }

        private float lat;

        public float Lat
        {
            get { return lat; }
            set { lat = value; }
        }

        private float lng;

        public float Lng
        {
            get { return lng; }
            set { lng = value; }
        }

        private string status;

        public string Status
        {
            get { return status; }
            set { status = value; }
        }

        private int questOrder;

        public int QuestOrder
        {
            get { return questOrder; }
            set { questOrder = value; }
        }

        private string duration;

        public string Duration
        {
            get { return duration; }
            set { duration = value; }
        }

        public const string NOT_CHECKED_IN_STATUS = "u";
        public const string START_STATUS = "s";
        public const string COMPLETE_STATUS = "e";

        public string IconUri
        {
            get 
            {
                string[] idString = iconID.Split('.');
                if (idString.Length < 2)
                {
                    if (IsolatedStorageSettings.ApplicationSettings.Contains(Constants.CURRENT_GAMEID))
                    {
                        string gameID = (string)IsolatedStorageSettings.ApplicationSettings[Constants.CURRENT_GAMEID];
                        return "/Confucius;component/assets/gameFiles/" + gameID + "/" + iconID + ".png";
                    }
                    else
                        return "/Confucius;component/assets/images/quest.png";
                }
                else
                {
                    if (IsolatedStorageSettings.ApplicationSettings.Contains(Constants.CURRENT_GAMEID))
                    {
                        string gameID = (string)IsolatedStorageSettings.ApplicationSettings[Constants.CURRENT_GAMEID];
                        return "/Confucius;component/assets/gameFiles/" + gameID + "/" + iconID;
                    }
                    else
                        return "/Confucius;component/assets/images/quest.png";
                }
            }
        }

        public Visibility ListVisibility
        {
            get
            {
                if (!status.Equals(NOT_CHECKED_IN_STATUS))
                    return Visibility.Visible;
                else
                    return Visibility.Collapsed;
            }
        }

        public Visibility FinishedListVisibility
        {
            get
            {
                if (status.Equals(COMPLETE_STATUS))
                    return Visibility.Visible;
                else
                    return Visibility.Collapsed;
            }
        }

        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return false;
            }

            // If parameter cannot be cast to this class return false.
            Quest p = obj as Quest;
            if ((System.Object)p == null)
            {
                return false;
            }

            // Return true if the fields match:
            return (questID == p.questID) && (status == p.status);
        }

        public override int GetHashCode()
        {
            return questID.GetHashCode() * (status.GetHashCode());
        }
    }
}
